#pragma once

template <typename T>
constexpr T bits_swap(T value) noexcept
{
    if constexpr (sizeof(T) == 1)
        return value;
    else if constexpr (sizeof(T) == 2)
        return __builtin_bswap16(value);
    else if constexpr (sizeof(T) == 4)
        return __builtin_bswap32(value);
    else if constexpr (sizeof(T) == 8)
        return __builtin_bswap64(value);
    else
        static_assert(sizeof(T) != sizeof(T), "Unsupported size for T");
}